/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:48
 */

package com.lenovo.mso2o.view;

import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;

/**
 * Created by hippo on 12/26/15.
 */
public class RightLeftSwipeDrawerLayout extends DrawerLayout implements SimpleGestureFilter.SimpleGestureListener{
    SimpleGestureFilter simpleGestureFilter;
    public RightLeftSwipeDrawerLayout(Context context) {
        super(context);
        simpleGestureFilter = new SimpleGestureFilter((AppCompatActivity) getContext(), this);
        simpleGestureFilter.setMode(SimpleGestureFilter.MODE_TRANSPARENT);
        simpleGestureFilter.setSwipeMinVelocity(1);
        simpleGestureFilter.setSwipeMinDistance(1);
    }

    public RightLeftSwipeDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        simpleGestureFilter = new SimpleGestureFilter((AppCompatActivity) getContext(), this);
        simpleGestureFilter.setMode(SimpleGestureFilter.MODE_TRANSPARENT);
        simpleGestureFilter.setSwipeMinVelocity(20);
        simpleGestureFilter.setSwipeMinDistance(10);
    }

    public RightLeftSwipeDrawerLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        simpleGestureFilter = new SimpleGestureFilter((AppCompatActivity) getContext(), this);
        simpleGestureFilter.setMode(SimpleGestureFilter.MODE_TRANSPARENT);
        simpleGestureFilter.setSwipeMinVelocity(20);
        simpleGestureFilter.setSwipeMinDistance(10);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent me){
        if(getTag() != null && (Boolean)getTag())
            this.simpleGestureFilter.onTouchEvent(me);
        return super.dispatchTouchEvent(me);
    }

    @Override
    public void onSwipe(int direction) {
        if(direction == SimpleGestureFilter.SWIPE_LEFT)
            if(isDrawerOpen(Gravity.LEFT)) {
                closeDrawer(Gravity.LEFT);
            }
    }

    @Override
    public void onDoubleTap() {

    }
}
